package cn.zzuli.test;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String  html="[\n" +
                "  {\n" +
                "    \"temp\": \"20℃/30℃\",\n" +
                "    \"weather\": \"晴转多云\",\n" +
                "    \"name\": \"上海\",\n" +
                "    \"pm\": \"80\",\n" +
                "    \"wind\": \"1级\"\n" +
                "  },\n" +
                "  {\n" +
                "    \"temp\": \"15℃/24℃\",\n" +
                "    \"weather\": \"晴\",\n" +
                "    \"name\": \"北京\",\n" +
                "    \"pm\": \"98\",\n" +
                "    \"wind\": \"3级\"\n" +
                "  },\n" +
                "  {\n" +
                "    \"temp\": \"26℃/32℃\",\n" +
                "    \"weather\": \"多云\",\n" +
                "    \"name\": \"广州\",\n" +
                "    \"pm\": \"30\",\n" +
                "    \"wind\": \"2级\"\n" +
                "  }\n" +
                "]";

        try {
            JSONArray  jsonArray = new JSONArray(html);
           for(int i = 0;i < jsonArray.length();i++){
               JSONObject jsonObject = (JSONObject) jsonArray.get(i);
               Test  weather= new Test();
               List<Test> weathers= new ArrayList<Test>();
               weather.setTemp(jsonObject.getString("temp"));
                weather.setWeather(jsonObject.getString("weather"));
                weather.setName(jsonObject.getString("name"));
                weather.setPm(jsonObject.getString("pm"));
                weather.setWind(jsonObject.getString("wind"));
                weathers.add(weather);
                System.out.println("888888888888888888888888");
               System.out.println(weather);


           }

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

}